<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
 <form th:action="@{/update_save}" th:each="user:${users}" method="post" onsubmit="return fun1()">
     <input name="id" type="hidden" th:value="${user.id}">
        <table border="1">
            <tr>
                <th>学生信息添加</th>
            </tr>
            <tr>
                <td>
                    用户姓名: <input name="name" type="text" th:value="${user.name}">
                </td>
            </tr>
            <tr>
                <td>
                    用户性别: <input name="gender" type="text" th:value="${user.gender}">
                </td>
            </tr>
            <tr>
                <td>
                    用户年龄: <input id="age" name="age" type="text" th:value="${user.age}" onclick="fun2()">
                </td>
            </tr>
            <tr>
                <th>
                    <input type="submit" value="保存">
                </th>
            </tr>
        </table>
    </form>
</body>
<script>
    function fun1(){
        let age = document.getElementById("age");
        let rule = /^[1-9]{1}[0-9]{0,2}$/
        if(rule.test(age.value) === false){
            age.value = "请输入数字"
            age.style = "color:red";
            return false
        }else{
            return true
        }
    }
    function fun2(){
        let age = document.getElementById("age");
        if(age.style.color === "red"){
            age.value="";
            age.style = "color:black"
        }
    }
</script>
</html>